package SunDayCoding.TestCode;

import java.util.Scanner;

public class TestGetNum {//
    public static void main(String[] args) {
        System.out.println("请输入一个任意N位整数");
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();//1234 /10 /10  /10 /10
       //1.判断位数
        int len=0;
        int numCopy=num;
        while(num>9)
        {
           num=num/10;
        }
        //------组织整数
        int r=1;//1234 1000  4
        for (int i = 1; i <= 3; i++) {
            r=r*10;
        }

        //------------- 1234  1000   456  100
        int numCopy1=numCopy % r;
        int sum=0;
        while(numCopy1!=0)
        {
            sum+=numCopy1%10;
            numCopy1/=10;
        }
        System.out.println("sum = " + sum);
    }
}
